import React from 'react';
import {message, Switch} from 'antd';
import {API} from "@/services/typings";
import {changeJobStatusAPI, updateSysJob} from "@/pages/job/job-manager/service";

interface JobStatusSwitchProps {
  record: API.ISysJob;
  tableRef: React.MutableRefObject<any>;
}

const JobStatusSwitch: React.FC<JobStatusSwitchProps> = ({record, tableRef}) => {
  const handleChange = async (checked: boolean) => {
    try {
      const newStatus = checked ? '0' : '1';
      // 这里替换为实际的API请求
      const {data} = await updateSysJob({...record, status: newStatus});
      if (data){
        message.success('状态更新成功');
        tableRef.current.reload();
      }
    } catch (error) {
      message.error('状态更新失败');
    }
  };

  return (
    <Switch
      checked={record.status === '0'}
      onChange={handleChange}
      checkedChildren="正常"
      unCheckedChildren="暂停"
    />
  );
};

export default JobStatusSwitch;
